package com.compass.doctor.ui.chat.viewholder;

import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;

import com.compass.doctor.R;
import com.compass.doctor.databinding.ChatMessageGiftViewHolderBinding;
import com.compass.doctor.ui.chat.attachment.GiftMessageAttachment;
import com.netease.yunxin.kit.chatkit.ui.common.MessageHelper;
import com.netease.yunxin.kit.chatkit.ui.databinding.ChatBaseMessageViewHolderBinding;
import com.netease.yunxin.kit.chatkit.ui.fun.view.message.viewholder.FunChatBaseMessageViewHolder;
import com.netease.yunxin.kit.chatkit.ui.model.ChatMessageBean;

/**
 * Description：
 * Date:2024/3/21 9:04
 */
public class GiftMessageViewHolder extends FunChatBaseMessageViewHolder {
    public static final String TAG = "InquiryViewHolder";
    ChatMessageGiftViewHolderBinding binding;
    GiftMessageAttachment attachment;

    public GiftMessageViewHolder(@NonNull ChatBaseMessageViewHolderBinding parent, int viewType) {
        super(parent, viewType);
    }

    @Override
    protected void addViewToMessageContainer() {
        binding = ChatMessageGiftViewHolderBinding.inflate(LayoutInflater.from(parent.getContext()), getMessageContainer(), true);

    }


    @Override
    public void bindData(ChatMessageBean message, ChatMessageBean lastMessage) {
        super.bindData(message, lastMessage);
        currentMessage = message;
        attachment = (GiftMessageAttachment) message.getMessageData().getMessage().getAttachment();
        if (attachment == null) {
            return;
        }


        //设置ViewHolder展示UI的内容
//
        binding.tvContentData.setText(attachment.getContentData());

    }



    @Override
    protected void onMessageBackgroundConfig(ChatMessageBean messageBean) {
        super.onMessageBackgroundConfig(messageBean);
        boolean isReceivedMsg = MessageHelper.isReceivedMessage(messageBean);
        View firstChild = baseViewBinding.messageContainer.getChildAt(0);
        if (isReceivedMsg) {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message);
        } else {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message_out);
        }
    }
}
